# -*- encoding:utf-8 -*-
# __author__ = 'chenyongbing'
# __poject__ = 'ops_platform'
# __datetime__ = '2022/5/11'
# __name__ = 'filters.py'
from django_filters.rest_framework import FilterSet
import django_filters

from .models import *
# Create your code here.


class DockerRepoFilter(FilterSet):
    """
    支持模糊搜索
    icontains，包含且忽略大小写
    """
    name = django_filters.CharFilter(field_name='name', lookup_expr='icontains')
    class Meta:
        # 指定模型
        models = DockerRepo
        # 指定需要模糊查询的字段
        fields = ['name']

class KubenetesFilter(FilterSet):
    """
    支持模糊搜索
    icontains，包含且忽略大小写
    """
    name = django_filters.CharFilter(field_name='name', lookup_expr='icontains')
    class Meta:
        # 指定模型
        models = Kubernetes
        # 指定需要模糊查询的字段
        fields = ['name']

class BusinessFilter(FilterSet):
    """
    支持模糊搜索
    icontains，包含且忽略大小写
    """
    name = django_filters.CharFilter(field_name='name', lookup_expr='icontains')
    code = django_filters.CharFilter(field_name='code', lookup_expr='icontains')
    id = django_filters.CharFilter(field_name='id')
    class Meta:
        # 指定模型
        models = Business
        # 指定需要模糊查询的字段
        fields = ['name', 'code']

class ProjectFilter(FilterSet):
    """
    支持模糊搜索
    icontains，包含且忽略大小写
    """
    name = django_filters.CharFilter(field_name='name', lookup_expr='icontains')
    code = django_filters.CharFilter(field_name='code', lookup_expr='icontains')
    business = django_filters.CharFilter(field_name='business')
    class Meta:
        # 指定模型
        models = Project
        # 指定需要模糊查询的字段
        fields = ['name', 'code', 'business']

class ServiceFilter(FilterSet):
    """
    支持模糊搜索
    icontains，包含且忽略大小写
    """
    name = django_filters.CharFilter(field_name='name', lookup_expr='icontains')
    code = django_filters.CharFilter(field_name='code', lookup_expr='icontains')
    business = django_filters.CharFilter(field_name='business')
    project = django_filters.CharFilter(field_name='project')
    class Meta:
        # 指定模型
        models = Service
        # 指定需要模糊查询的字段
        fields = ['name', 'code', 'business', 'project']



class LobPermFilter(FilterSet):
    """
    支持模糊搜索
    icontains，包含且忽略大小写
    """
    business = django_filters.CharFilter(field_name='business')
    username = django_filters.CharFilter(field_name='user.username')
    class Meta:
        # 指定模型
        models = LobPerm
        # 指定需要模糊查询的字段
        fields = ['business', 'username']



class EnvironmentFilter(FilterSet):
    """
        支持模糊搜索
        icontains，包含且忽略大小写
        """
    name = django_filters.CharFilter(field_name='name', lookup_expr='icontains')

    class Meta:
        # 指定模型
        models = Environment
        # 指定需要模糊查询的字段
        fields = ['name']